package com.dreamlin.basepro.common;

import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.util.TypedValue;

import me.jessyan.autosize.AutoSizeConfig;

public class DensityUtils {
    private static DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics();
    private static float scale = (float) AutoSizeConfig.getInstance().getInitScreenWidthDp()
            / (float) AutoSizeConfig.getInstance().getDesignWidthInDp();

    public static int dp2px(float dp) {
        return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, displayMetrics) * scale);
    }

    public static int sp2px(float sp) {
        return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, displayMetrics) * scale);
    }

    public static int getScreenWidth() {
        return displayMetrics.widthPixels;
    }

    public static int getScreenHeight() {
        return displayMetrics.heightPixels;
    }

}
